package xin.clips.web.controller.gy;

import cn.hutool.core.collection.CollUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import xin.clips.common.annotation.Log;
import xin.clips.common.annotation.VisistLog;
import xin.clips.common.enums.BusinessType;
import xin.clips.common.core.controller.BaseController;
import xin.clips.common.core.domain.AjaxResult;
import xin.clips.common.core.page.TableDataInfo;
import xin.clips.common.utils.poi.ExcelUtil;
import xin.clips.system.domain.gy.GyDeviceMgt;
import xin.clips.system.domain.gy.GyWorkOrder;
import xin.clips.system.service.gy.IGyDeviceMgtService;
import xin.clips.system.service.gy.IGyWorkOrderService;

import java.util.List;

/**
 * 工单信息Controller
 *
 * @author clips
 * @date 2023-03-10
 */
@Controller
@RequestMapping("/gy/workOrder")
public class GyWorkOrderController extends BaseController
{
    private String prefix = "gy/workOrder";

    @Autowired
    private IGyWorkOrderService gyWorkOrderService;

    @RequiresPermissions("gy:workOrder:view")
    @VisistLog(title = "工单信息")
    @GetMapping()
    public String workOrder()
    {
        return prefix + "/workOrder";
    }

    /**
     * 查询工单信息列表
     */
    @RequiresPermissions("gy:workOrder:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GyWorkOrder gyWorkOrder)
    {
        startPage();
        List<GyWorkOrder> list = gyWorkOrderService.selectGyWorkOrderList(gyWorkOrder);
        return getDataTable(list);
    }

    /**
     * 导出工单信息列表
     */
    @RequiresPermissions("gy:workOrder:export")
    @Log(title = "工单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GyWorkOrder gyWorkOrder)
    {
        List<GyWorkOrder> list = gyWorkOrderService.selectGyWorkOrderList(gyWorkOrder);
        ExcelUtil<GyWorkOrder> util = new ExcelUtil<GyWorkOrder>(GyWorkOrder.class);
        return util.exportExcel(list, "工单信息数据");
    }

    /**
     * 新增工单信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存工单信息
     */
    @RequiresPermissions("gy:workOrder:add")
    @Log(title = "工单信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GyWorkOrder gyWorkOrder)
    {
        return  gyWorkOrderService.insertGyWorkOrder(gyWorkOrder);
    }

    /**
     * 修改工单信息
     */
    @RequiresPermissions("gy:workOrder:edit")
    @GetMapping("/edit/{workId}")
    public String edit(@PathVariable("workId") Long workId, ModelMap mmap)
    {
        GyWorkOrder gyWorkOrder = gyWorkOrderService.selectGyWorkOrderByWorkId(workId);
        mmap.put("gyWorkOrder", gyWorkOrder);
        return prefix + "/edit";
    }

    /**
     * 修改保存工单信息
     */
    @RequiresPermissions("gy:workOrder:edit")
    @Log(title = "工单信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GyWorkOrder gyWorkOrder)
    {
        return toAjax(gyWorkOrderService.updateGyWorkOrder(gyWorkOrder));
    }

    /**
     * 审核详情
     */
   // @RequiresPermissions("gy:workOrder:detail")
    @GetMapping("/detail")
    public String detail(@RequestParam("workId") String workId, ModelMap mmap) {
        GyWorkOrder workOrder= gyWorkOrderService.selectGyWorkOrderByWorkId(Long.valueOf(workId));
        mmap.put("workOrder", workOrder);
        return prefix + "/detail";
    }

    /**
     * 删除工单信息
     */
    @RequiresPermissions("gy:workOrder:remove")
    @Log(title = "工单信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(gyWorkOrderService.deleteGyWorkOrderByWorkIds(ids));
    }
}
